<?php defined('IN_ADMIN') or exit('No permission resources.');?>
<?php include $this->admin_tpl('header', 'admin');?>

<h3 style="padding-left: 20px;padding-top: 10px">
	<?=$data['name']?>——<?php if($_GET['source_type']==1){echo '资讯';}elseif ($_GET['source_type']==2){echo '视频';}elseif ($_GET['source_type']==3){echo '图片集';}?>绑定<?php //if($data['is_activity']==1){ echo L("activity");}else{ echo L("contest");}?>
	<a href="./index.php?m=contest&c=manage&a=init&is_activity=<?=$data['is_activity']?>" style="font-size:14px;color: #0000FF"><em>返回上一级</em></a>
</h3>

<div class="subnav">
	<div class="content-menu ib-a blue line-x">
		<a href="?m=contest&c=source&a=init&source_type=1&contest_id=<?=$id?>" <?php if(ROUTE_A=="init"&&$source_type==1){ ?>   class="on"<?php } ?><em>资讯</em></a>
		<span>|</span>
		<a href="?m=contest&c=source&a=init&source_type=2&contest_id=<?=$id?>" <?php if(ROUTE_A=="init"&&$source_type==2){ ?>   class="on"<?php } ?>  > <em>视频</em></a>
		<span>|</span>
		<a href="?m=contest&c=source&a=init&source_type=3&contest_id=<?=$id?>" <?php if(ROUTE_A=="init"&&$source_type==3){ ?>   class="on"<?php } ?> ><em>图片集</em></a>
		<span>|</span>
		<a href="./index.php?m=contest&c=video&a=init&contest_id=<?=$id?>"   ><em>视频集</em></a>


	</div>
</div>

<div class="pad-lr-10">

	<div id="searchid" style="">
		<form name="searchform" action="" method="get" >
			<input type="hidden" value="<?php echo ROUTE_M;?>" name="m">
			<input type="hidden" value="<?php echo ROUTE_C;?>" name="c">
			<input type="hidden" value="<?php echo ROUTE_A;?>" name="a">
			<input type="hidden" value="<?php echo $source_type;?>" name="source_type">
			<input type="hidden" value="1" name="search">
			<input type="hidden" value="<?=$id?>" name="contest_id">
			<input type="hidden" value="<?php echo $pc_hash;?>" name="pc_hash">
			<table width="100%" cellspacing="0" class="search-form">
				<tbody>
				<tr>
					<td>
                        <button type="button" style="float:right;margin-right:20px;margin-top:10px;" onclick="javascript:openwinx('?m=contest&c=source&a=add&contest_id=<?=$contest_id?>&source_type=<?=$source_type?>&flag=contest&pc_hash=<?php echo $_SESSION['pc_hash'];?>','')" ><em>添加<?= $btn_info?></em></button>
						<button type="button" style="float:right;margin-right:20px;margin-top:10px;" onclick="showSelect()" ><em>选择<?= $btn_info?></em></button>
						<span style="clear: both"></span>
						<script>
							function showAdd(){
								window.top.art.dialog({
										id: 'add',
										iframe: '?m=contest&c=source&a=add&contest_id=<?=$id?>&source_type=<?=$source_type?>&flag=contest',
										title: '添加<?= $btn_info?>',
										width: '900',
										height: '500',
										lock: true
									},
									function() {
										var d = window.top.art.dialog({
											id: 'add'
										}).data.iframe;
										var form = d.document.getElementById('dosubmit');
										form.click();
										return false;
									},
									function() {
										window.top.art.dialog({
											id: 'add'
										}).close()
									});
							}
							function  showSelect(){
								window.top.art.dialog({
										id: 'select',
										iframe: '?m=contest&c=source&a=bindView&contest_id=<?=$id?>&source_type=<?=$source_type?>&flag=contest',
										title: '选择<?= $btn_info?>',
										width: '900',
										height: '500',
										lock: true
									},
									function() {
										var d = window.top.art.dialog({
											id: 'select'
										}).data.iframe;
										var relation = d.document.getElementById('relation');


										if(relation.value!=""){
											$.ajax({
												type:"get",
												url:"?m=contest&c=source&a=bindAction&source_type=<?=$source_type?>'&contest_id=<?=$id?>&relation="+relation.value+"&pc_hash=<?php echo $_SESSION['pc_hash'];?>",
												dataType: "json",
												success:function(data){
													if(data['status']){
														window.top.art.dialog({
															id: 'select'
														}).close()
														window.location.reload();
													}else{
														alert(data['msg']);
														return false;
													}
												}
											})
										}else{
											return true;
										}

									},
									function() {
										window.top.art.dialog({
											id: 'select'
										}).close()
									});
							}
						</script>


						<div class="explain-col">
                            <?php echo L('type')?>：
							<select name="typeid" >
							<option value="0">请选择</option>
							<?php echo $select_categorys;?>
							</select>
							<?php echo L('title');?>：<input name="title" type="text" value="<?php echo $_GET['title']?>" class="input-text" />
							<input type="submit" name="search" class="button" value="<?php echo L('search');?>" />
						</div>
					</td>
				</tr>
				</tbody>
			</table>
		</form>
	</div>

	<form name="myform" id="myform" action="" method="post" >
		<div class="table-list">
			<table width="100%">
				<thead>
				<tr>
					<th width="16"><input type="checkbox" value="" id="check_box" onclick="selectall('ids[]');"></th>
					<th width="57"><?php echo L('listorder');?></th>
					<th><?php echo L('title');?></th>
					<th width="100"><?php echo "是否置顶"?></th>
    			    <th width="120"><?php echo L('information_image_cover');?></th>
					<th width="168"><?php echo L('create_time');?></th>
					<th width="120"><?php echo '上次编辑者';?></th>
					<th width="120"><?php echo '绑定者';?></th>
					<th width="100"><?php echo L('operations_manage');?></th>
				</tr>
				</thead>
				<tbody>
				<?php
				if(!empty($sourceinfo)) {

					foreach ($sourceinfo as $k=> $r) {
						?>
						<tr>
							<td align="center"><input class="inputcheckbox " name="ids[]" value="<?php echo $r['cid'];?>" type="checkbox"></td>
							<td align='center'><input name='listorders[<?php echo $r['cid'];?>]' type='text' size='3' value='<?php echo $r['sort'];?>' class='input-text-c'></td>

							<td align='center' ><?php echo $r['title'];?></td>
							<td align='center' ><a href="javascript:void(0)" data-id="<?=$r['cid']?>" data-top="<?=$r['is_top']?>" onclick="changeTop(this)"><?php if($r['is_top']==1){echo "是";}else{echo "否";} ;?></a></td>
		                    <td align='center'><?php if(!empty($r['image_cover'])){?><img src="<?php echo $r['image_cover'];?>" height="60"/><?php }else{echo '暂无数据！';}?></td>
							<td align='center'><?php if(empty($r['create_time'])){echo "暂无数据！";}else{echo $r['create_time'];}?></td>
							<td align='center'><?php if(empty($r['updated_by'])){echo "暂无数据！";}else{echo $administrators[$r['updated_by']];}?></td>
							<td align='center'><?php if(empty($r['supdated_by'])){echo "暂无数据！";}else{echo $administrators[$r['supdated_by']];}?></td>
							<td align='center'><a href="?m=contest&c=source&a=del&id=<?php echo $r['cid']?>" onClick="return confirm('<?php echo L('confirm', array('message' => new_addslashes($r['title'])))?>')"><?php echo L('cancel_bind')?></a></td>

						</tr>
					<?php }
				}else{
    echo "<tr><td colspan='8' style='color:red;font-size:18px;text-align:center;'><span>暂无数据！</span></td></tr>";
}
				?>
				</tbody>
			</table>
			<div class="btn"><label for="check_box"><?php echo L('selected_all');?>/<?php echo L('cancel');?></label>
				<input type="hidden" value="<?php echo $pc_hash;?>" name="pc_hash">
				<input type="button" class="button" value="<?php echo L('listorder');?>" onclick="myform.action='?m=contest&c=source&a=listorder&dosubmit=1&steps=<?php echo $steps;?>';myform.submit();"/>
				<input type="button" class="button" value="<?php echo L('cancel_bind');?>" onclick="myform.action='?m=contest&c=source&a=deleteAll&dosubmit=1&steps=<?php echo $steps;?>';return confirm_delete()"/>
			</div>
			<div id="pages"><?php echo $pages;?></div>
		</div>
	</form>
</div>
<script language="javascript" type="text/javascript" src="<?php echo JS_PATH?>cookie.js"></script>
<script type="text/javascript">

	function confirm_delete(){
		var flag_cancelBind =  '';
		$(".inputcheckbox").each(function(i){
			if(this.checked){
				flag_cancelBind = true;
			}
		});
		if(!flag_cancelBind){
			alert("请先选中要删除的数据！");
			return false;
		}
		if(confirm('您确认删除选中信息吗？')) $('#myform').submit();
	}

	function changeTop(obj){
		var id=$(obj).attr("data-id");
		var top=$(obj).attr("data-top");
		//top为现在状态
		var msg="";
		if(top==1){
			top=0;
			msg="否";

		}else{
			top=1;
			msg="是";
		}

		$.ajax({
			type:"get",
			url:"?m=contest&c=source&a=top&id="+id+"&is_top="+top+"&pc_hash=<?php echo $_SESSION['pc_hash'];?>",
			dataType: "json",
			success:function(data){
				if(data['status']){
						$(obj).text(msg);
					    $(obj).attr("data-top",top);
				}else{
					alert(data['msg']);
					return false;
				}
			}
		})
	}
</script>
<script type="text/javascript">
    /*
     *function：根据cookie值来判断表单、ajax等成功执行时，重新加载窗口 
     * author：吴发顶
     * time：2017-06-08 10:56:13
     */
	setcookie('refersh_time', 0);
	function refersh_window() {
		var refersh_time = getcookie('refersh_time');
		if(refersh_time==1) {
			window.location.reload();
		}
	}
	setInterval("refersh_window()", 3000);
</script>
</body>
</html>